$(document).ready(function () {



    //画图结束
    //checkbox复选 全选和清除
    $('#allchoose1').click(function(){
        $("#fishchoice input").each(function () {
            $(this).prop('checked', true);
        });
    });
    $('#allunchoose1').click(function(){
        $("#fishchoice input").each(function () {
            $(this).prop('checked', false);
        });
    });
    $('#allchoose2').click(function(){
        $("#livingchoice input").each(function () {
            $(this).prop('checked', true);
        });
    });
    $('#allunchoose2').click(function(){
        $("#livingchoice input").each(function () {
            $(this).prop('checked', false);
        });
    });
    $('#allchoose3').click(function(){
        $("#searchchoice input").each(function () {
            $(this).prop('checked', true);
        });
    });
    $('#allunchoose3').click(function(){
        $("#searchchoice input").each(function () {
            $(this).prop('checked', false);
        });
    });
    $('#allchoose4').click(function(){
        $("#yearschoice input").each(function () {
            $(this).prop('checked', true);
        });
    });
    $('#allunchoose4').click(function(){
        $("#yearschoice input").each(function () {
            $(this).prop('checked', false);
        });
    });
    //
    //分析按钮
    $("#analysis").click(function(){
        //判断是否有选择必选项
        var flag=0;
        /*$("#fishchoice input").each(function () {
            if($(this).is(':checked'))
            {
                flag=1;
            }
        });
        if(flag==0)
        {
            alert("请至少选择一个鱼类样本！");
            return false;
        }
        flag=0;
        $("#livingchoice input").each(function () {
            if($(this).is(':checked'))
            {
                flag=1;
            }
        });
        if(flag==0)
        {
            alert("请至少选择一个生物学样本！");
            return false;
        }
        flag=0;
        $("#searchchoice input").each(function () {
            if($(this).is(':checked'))
            {
                flag=1;
            }
        });
        if(flag==0)
        {
            alert("请至少选择一个监测点！");
            return false;
        }
        flag=0;
        $("#yearschoice input").each(function () {
            if($(this).is(':checked'))
            {
                flag=1;
            }
        });
        if(flag==0)
        {
            alert("请至少选择一个年份！");
            return false;
        }*/
        $.ajax({									//修改采样水层
            type: "post",
            async: false,
            url: "DataAnalysis.action",
            data: {
                "weight": 1,
                "length": 1,
            },
            success: function (result) {
                $("#resultfont").show();
                // 第一张图
                var myChart = echarts.init(document.getElementById("main"));

                // 指定图表的配置项和数据
                var category = [];
                var dottedBase = +new Date();
                var lineData = [];
                var barData = [];
                for (var i = 0; i < 20; i++) {
                    var date = new Date(dottedBase += 1000 * 3600 * 24);
                    category.push([
                        date.getFullYear(),
                        date.getMonth() + 1,
                        date.getDate()
                    ].join('-'));
                    var b = Math.random() * 200;
                    var d = Math.random() * 200;
                    barData.push(b)
                    lineData.push(d + b);
                }
                // option
                var option = {
                    backgroundColor: '#0f375f',
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {
                            type: 'shadow',
                            label: {
                                show: true,
                                backgroundColor: '#333'
                            }
                        }
                    },
                    legend: {
                        data: ['line', 'bar'],
                        textStyle: {
                            color: '#ccc'
                        }
                    },
                    xAxis: {
                        data: category,
                        axisLine: {
                            lineStyle: {
                                color: '#ccc'
                            }
                        }
                    },
                    yAxis: {
                        splitLine: {show: false},
                        axisLine: {
                            lineStyle: {
                                color: '#ccc'
                            }
                        }
                    },
                    series: [{
                        name: 'line',
                        type: 'line',
                        smooth: true,
                        showAllSymbol: true,
                        symbol: 'emptyCircle',
                        symbolSize: 15,
                        data: lineData
                    }, {
                        name: 'bar',
                        type: 'bar',
                        barWidth: 10,
                        itemStyle: {
                            normal: {
                                barBorderRadius: 5,
                                color: new echarts.graphic.LinearGradient(
                                    0, 0, 0, 1,
                                    [
                                        {offset: 0, color: '#14c8d4'},
                                        {offset: 1, color: '#43eec6'}
                                    ]
                                )
                            }
                        },
                        data: barData
                    }, {
                        name: 'line',
                        type: 'bar',
                        barGap: '-100%',
                        barWidth: 10,
                        itemStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(
                                    0, 0, 0, 1,
                                    [
                                        {offset: 0, color: 'rgba(20,200,212,0.5)'},
                                        {offset: 0.2, color: 'rgba(20,200,212,0.2)'},
                                        {offset: 1, color: 'rgba(20,200,212,0)'}
                                    ]
                                )
                            }
                        },
                        z: -12,
                        data: lineData
                    }, {
                        name: 'dotted',
                        type: 'pictorialBar',
                        symbol: 'rect',
                        itemStyle: {
                            normal: {
                                color: '#0f375f'
                            }
                        },
                        symbolRepeat: true,
                        symbolSize: [12, 4],
                        symbolMargin: 1,
                        z: -10,
                        data: lineData
                    }]
                };
                // 使用刚指定的配置项和数据显示图表。
                myChart.setOption(option);
                //第二张图
                var myChart1 = echarts.init(document.getElementById("main1"));
                var option1 = {
                    legend: {
                        data:['体重(g)与体长(mm)关系']
                    },
                    tooltip: {
                        trigger: 'axis',
                        formatter: "(Length,Weight) : {c}"
                    },
                    grid: {
                        left: '3%',
                        right: '15%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: {
                        name: 'L(mm)',
                        min:0,
                        max:8,
                        type: 'value',
                        axisLine: {onZero: false},

                    },
                    yAxis: {
                        name: 'W(g)',
                        min:0,
                        max:300,
                        type: 'value',
                        axisLine: {onZero: false},

                        boundaryGap: false,
                    },
                    series: [
                        {
                            name: '体重(g)与体长(mm)关系',
                            type: 'line',
                            smooth: true,
                            lineStyle: {
                                normal: {
                                    width: 3,
                                    shadowColor: 'rgba(0,0,0,0.4)',
                                    shadowBlur: 10,
                                    shadowOffsetY: 10
                                }
                            },
                            data:[[0,1], [1,2], [2,4], [3,8], [4,16], [5,32], [6,64], [7,128], [8,256]]
                        }
                    ]
                };
                myChart1.setOption(option1);
            }
        });
    });
});